package com.atguigu.gmall.task.scheduled;

import com.atguigu.gmall.common.constant.MqConst;
import com.atguigu.gmall.common.service.RabbitService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author fxz
 */
@Component
@EnableScheduling
@Slf4j
@RequiredArgsConstructor
public class ScheduledTask {

	private final RabbitService rabbitService;

	/**
	 * 每天凌晨1点执行
	 */
	@Scheduled(cron = "0/10 * * * * ?")
	// @Scheduled(cron = "0 0 1 * * ?")
	public void task1() {
		log.info("真帅...");
		rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK, MqConst.ROUTING_TASK_1, "");
	}

	/**
	 * 清空缓存
	 */
	@Scheduled(cron = "0 0 18 * * ?")
	public void clearRedis() {
		log.info("清空缓存...");
		rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK, MqConst.ROUTING_TASK_18, "");
	}

}